package someTestExcemple.tcp;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Server1 {
    public static List<Socket> sockets = new ArrayList<Socket>();
    public static void main(String[] args) throws IOException {
        System.out.println("服务器启动...");
        System.out.println(Arrays.toString(sockets.toArray()));
        //创建一个服务器端Socket，即ServerSocket，指定绑定的端口，并监听此端口
        ServerSocket serverSocket = new ServerSocket(8888);
        while (true) {
           Socket socket =serverSocket.accept();
           sockets.add(socket);
            System.out.println(Arrays.toString(sockets.toArray()));
           System.out.println("有人上线了:" + socket.getRemoteSocketAddress());
           new Thread(new ServerReaderThread(socket)).start();
       }
    }
}
